#!/usr/bin/python
import cgi
import cgitb
import os
from pygallib import usersession
from pygallib import layoutlib
from pygallib import albumlib
from pygallib import userlib
from pygallib import picturelib
from pygallib.userlib import ActivationError

# Enable debug print
cgitb.enable()

logged_in = usersession.logged_in()

headers = {}
headers["Content-type"] = "text/html"
layoutlib.print_http_headers(headers)
layoutlib.print_page_open("PyGallery - Home")
print("<body>")
menu = []
menu.append(("Home", "gallery.cgi"))
layoutlib.print_page_header(menu)
print('<div id="page_body">')

# Get the fields from url
fields = cgi.FieldStorage()
if "id" in fields:
  activation_id = fields["id"].value
  try:
    userlib.activate_user(activation_id)
    print('<p>Activation successful!</p>')
  except ActivationError:
    print('<p>Activation failed.</p>')
else:
  print('<p>Go to the <a href="gallery.cgi">gallery</a></p>')

print('</div>')
layoutlib.print_page_close()
